﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Windows.Forms;

    public class clsSoDuDauKyTaiSan
    {
        private string mDienGiai = "";
        private string mKhoa = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaDonVi = "";
        private string mKhoaNguoiDung = "";
        private string mKhoaTKChiPhi = "";
        private string mKhoaTKKhauHao = "";
        private string mKhoaTKNguyenGia = "";
        private string mLoaiTien = "";
        private string mNamThang = "";
        private double mSoDuCo = 0.0;
        private double mSoDuCoNT = 0.0;
        private double mSoDuNo = 0.0;
        private double mSoDuNoNT = 0.0;
        private double mTyGia = 0.0;

        public bool DelData(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, pKhoa);
                commandParameters[1] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SoDuDauKyTaiSanDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[1].Value, 0, false))
                {
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetList(string pNamThang)
        {
            IDataParameter parameter = null;
            DataTable table;
            try
            {
                string commandText = "SELECT SDDK.KHOA, SDDK.KHOATKNGUYENGIA KHOATK, TKNG.SOTAIKHOAN TENTK, SDDK.KHOADOITUONG KHOADT, TS.TENVIET TENDT,       SDDK.SODUNO, SDDK.SODUCO  FROM GL_SODUDAUKYTAISAN SDDK  JOIN DM_TAIKHOAN TKNG ON SDDK.KHOATKNGUYENGIA = TKNG.KHOA  JOIN FA_TAISANCODINH TS ON SDDK.KHOADOITUONG = TS.KHOA  WHERE SDDK.NAMTHANG = '" + pNamThang + "'  UNION ALL  SELECT SDDK.KHOA, SDDK.KHOATKNGUYENGIA KHOATK, TKKH.SOTAIKHOAN TENTK, SDDK.KHOADOITUONG KHOADT, TS.TENVIET TENDT,       SDDK.SODUNO, SDDK.SODUCO  FROM GL_SODUDAUKYTAISAN SDDK  JOIN DM_TAIKHOAN TKKH ON SDDK.KHOATKKHAUHAO = TKKH.KHOA  JOIN FA_TAISANCODINH TS ON SDDK.KHOADOITUONG = TS.KHOA  WHERE SDDK.NAMTHANG = '" + pNamThang + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[] { parameter }).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                string commandText = "SELECT * FROM GL_SoDuDauKyTaiSan WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, commandParameters);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mNamThang = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaTKNguyenGia = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKKhauHao = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKChiPhi = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mSoDuNo = Conversions.ToDouble(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoDuNoNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoDuCo = Conversions.ToDouble(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetDecimal));
                    this.mSoDuCoNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNguoiDung = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x10];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[3] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[4] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[5] = DBHelper.createParameter("@KhoaTKNguyenGia", DbType.Int64, ParameterDirection.Input, this.mKhoaTKNguyenGia);
                commandParameters[6] = DBHelper.createParameter("@KhoaTKKhauHao", DbType.Int64, ParameterDirection.Input, this.mKhoaTKKhauHao);
                commandParameters[7] = DBHelper.createParameter("@KhoaTKChiPhi", DbType.Int64, ParameterDirection.Input, this.mKhoaTKChiPhi);
                commandParameters[8] = DBHelper.createParameter("@SoDuNo", DbType.Date, ParameterDirection.Input, this.mSoDuNo);
                commandParameters[9] = DBHelper.createParameter("@SoDuNoNT", DbType.Date, ParameterDirection.Input, this.mSoDuNoNT);
                commandParameters[10] = DBHelper.createParameter("@SoDuCo", DbType.Date, ParameterDirection.Input, this.mSoDuCo);
                commandParameters[11] = DBHelper.createParameter("@SoDuCoNT", DbType.Date, ParameterDirection.Input, this.mSoDuCoNT);
                commandParameters[12] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[13] = DBHelper.createParameter("@KhoaNguoiDung", DbType.Int64, ParameterDirection.Input, this.mKhoaNguoiDung);
                commandParameters[14] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[15] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SoDuDauKyTaiSan", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[15].Value, 0, false))
                {
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaNguoiDung
        {
            get
            {
                return this.mKhoaNguoiDung;
            }
            set
            {
                this.mKhoaNguoiDung = value;
            }
        }

        public string KhoaTKChiPhi
        {
            get
            {
                return this.mKhoaTKChiPhi;
            }
            set
            {
                this.mKhoaTKChiPhi = value;
            }
        }

        public string KhoaTKKhauHao
        {
            get
            {
                return this.mKhoaTKKhauHao;
            }
            set
            {
                this.mKhoaTKKhauHao = value;
            }
        }

        public string KhoaTKNguyenGia
        {
            get
            {
                return this.mKhoaTKNguyenGia;
            }
            set
            {
                this.mKhoaTKNguyenGia = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public double SoDuCo
        {
            get
            {
                return this.mSoDuCo;
            }
            set
            {
                this.mSoDuCo = value;
            }
        }

        public double SoDuCoNT
        {
            get
            {
                return this.mSoDuCoNT;
            }
            set
            {
                this.mSoDuCoNT = value;
            }
        }

        public double SoDuNo
        {
            get
            {
                return this.mSoDuNo;
            }
            set
            {
                this.mSoDuNo = value;
            }
        }

        public double SoDuNoNT
        {
            get
            {
                return this.mSoDuNoNT;
            }
            set
            {
                this.mSoDuNoNT = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }
    }
}

